package net.yc.web.imalachat.push.bean.db;

import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.time.LocalDateTime;

/**
 * @author: lyc
 * @data: 2021-12-18  16:54
 * @Description: 用来实现用户和用户之间的关注的多对多关系，相当于一个代理商
 */
@Entity
@Table(name = "TB_USER_FOLLOW")
public class UserFollow {
    @Id
    @PrimaryKeyJoinColumn
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid2")
    @Column(updatable = false, nullable = false)
    private String id;

    /**
     * 定义一个发起人，你关注某人，这里就你自己
     * 多对一 ——> 你可以关注很多人，你得每一次关注都是一条纪录
     * 你可以创建很多关注的信息，所有都是多对一
     * 这里的多对一是：User 对应多个 UserFollow
     */
    @ManyToOne(optional = false)
    // 定义关联的表字段名为originId，对应的应该是User.id
    // 定义的是数据库中的存储字段
    @JoinColumn(name = "originId")
    private User origin;
    // 把这个列提取到我们的Module当中
    @Column(nullable = false, updatable = false, insertable = false)
    private String originId;

    /**
     * 定义关注的目标，你关注的人
     * 也是多对一的关系，可以被很多人关注，每一次关注都是一条记录
     * 多个UserFollow 对应User
     */
    @ManyToOne(optional = false)
    // targetId，对应的应该是User.id
    @JoinColumn(name = "targetId")
    private User target;
    @Column(nullable = false, updatable = false, insertable = false)
    private String targetId;

    // 对target的备注，可以为空
    @Column
    private String alias;

    // 定义为创建时间戳在创建的时候已经写入
    @CreationTimestamp
    @Column(nullable = false)
    private LocalDateTime createAt = LocalDateTime.now();

    // 定义更新时间戳在创建的时候已经写入
    @UpdateTimestamp
    @Column(nullable = false)
    private LocalDateTime updateAt = LocalDateTime.now();

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public User getOrigin() {
        return origin;
    }

    public void setOrigin(User origin) {
        this.origin = origin;
    }

    public String getOriginId() {
        return originId;
    }

    public void setOriginId(String originId) {
        this.originId = originId;
    }

    public User getTarget() {
        return target;
    }

    public void setTarget(User target) {
        this.target = target;
    }

    public String getTargetId() {
        return targetId;
    }

    public void setTargetId(String targetId) {
        this.targetId = targetId;
    }

    public String getAlias() {
        return alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public LocalDateTime getCreateAt() {
        return createAt;
    }

    public void setCreateAt(LocalDateTime createAt) {
        this.createAt = createAt;
    }

    public LocalDateTime getUpdateAt() {
        return updateAt;
    }

    public void setUpdateAt(LocalDateTime updateAt) {
        this.updateAt = updateAt;
    }

    @Override
    public String toString() {
        return "UserFollow{" +
                "id='" + id + '\'' +
                ", origin=" + origin +
                ", originId='" + originId + '\'' +
                ", target=" + target +
                ", targetId='" + targetId + '\'' +
                ", alias='" + alias + '\'' +
                ", createAt=" + createAt +
                ", updateAt=" + updateAt +
                '}';
    }

}
